<template>
	<view>
		<z-nav-bar title="赛事详情"></z-nav-bar>
		<view class="title">{{ info.title }}</view>
		<view class="content">
			<image class="one" :src="setting.oss_pub_domain + info.coverImage" v-if="info.num == 1" />
			<view class="three" v-else>
				<image :src="setting.oss_pub_domain + val" v-for="(val, key) in info.img" :key="key" />
			</view>
			<text>
				{{ info.content }}
			</text>
			<view class="uni-585C66 flex_fe uni-mt-16">
				{{ info.createTime }}
			</view>
		</view>
		<view class="btn">
			<view class="agree" @click="giveLike">
				<image :src="`${setting.sImgUrl}/agree.png`"></image>
				<text>{{ (info.praiseNum || 0) > 999 ? '999+' : (info.praiseNum || 0) }}</text>
			</view>
			<!-- #ifdef MP-WEIXIN -->
			<button open-type="share">
				<image :src="`${setting.sImgUrl}/share.png`"></image>
			</button>
			<!-- #endif -->
			<!-- #ifdef APP-PLUS || H5-->
			<image :src="`${setting.sImgUrl}/share.png`" @click="shareArticles"></image>
			<!-- #endif -->
		</view>
	</view>
</template>

<script>
import { getGameDetail, getGamePraise, appShareScuess } from '@/api/student';
export default {
	data() {
		return {
			id: 4,
			info: {
				title: ''
			}
		};
	},
	methods: {
		fetchData() {
			getGameDetail({ id: this.id }).then((res) => {
				this.info = res;
				this.info.img = this.info.coverImage.split(',');
				this.info.num = this.info.img.length;
			});
		},
		giveLike() {
			getGamePraise(this.info.id).then((res) => {
				this.tools.alert('点赞成功');
				this.info.praiseNum += 1
			});
		},
		shareArticles() {
			uni.share({
				provider: 'weixin',
				scene: 'WXSceneSession',
				type: 5,
				imageUrl: 'http://golfpub.jgtygolf.com/app-img/logo.png',
				title: '降杆教育',
				miniProgram: {
					id: 'gh_6be15b82eac6',
					path: '/pages/student/find/articles-detail?id=' + this.id,
					webUrl: 'http://golfpub.jgtygolf.com/app-img/logo.png',
					type: 1
				},
				success: (ret) => {
					appShareScuess();
				}
			});
		}
	},
	onLoad(option) {
		this.id = option.id;
	},
	onShow() {
		this.fetchData();
	},
	onShareAppMessage() {
		appShareScuess();
		return {
			title: this.info.title,
			path: '/pages/student/find/articles-detail?id=' + this.id
		};
	}
};
</script>

<style lang="scss" scoped>
@import './css/articles.css';
</style>
